<style lang="less">
    .title-text span {
        display: block;
        position: relative;
        color: black;
        font-weight: bold;
        text-align: center;
    }
    .title-text span:before, .title-text span:after {
        content: '';
        position: absolute;
        top: 50%;
        background: #dfdfdf;
        width: 44%;
        height: 1px;
    }
    .title-text span:before {
        left: 0;
    }
    .title-text span:after {
        right: 0;
    }
</style>
<template >
    <div style="background-color: rgb(255,255,255)">
        <Tabs type="card"  @on-click="clickType">
            <TabPane label="审核页面"></TabPane>
            <TabPane label="影像资料"></TabPane>
        </Tabs>
        <div class="addInfo" style="display: block" v-if="index==0">
            <h2 class="title-text" style="text-align: center"><span >审核意见</span></h2>
            <Row style="margin-top: 1%;border: 1px solid #dcdee2; border-color: #e8eaec;    margin: 8px;">
                <Form ref="netCarCompanyForm" :model="netCarCompanyForm" :rules="companyFormValidate"  :label-width="160">
                    <Row style="padding-top: 11px">
                        <i-col span="12">
                            <FormItem label="审核意见" prop="status"  style="margin-left: 40%" >
                                <Select v-model="netCarCompanyForm.status" @on-change="changeStatus(netCarCompanyForm.status)" filterable  style="    width: 200px;" size="default">
                                    <Option v-for="item in statusList" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                        <i-col span="6">
                            <Button @click="closeThisTag" size="large"  type="primary" style=" float: right;">返回</Button>
                            <Button @click="Commit('netCarCompanyForm')" size="large" type="primary" style=" float: right;margin-right:24px;">提交</Button>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="12">
                            <FormItem label="备注" prop="examineRemark"  style="margin-left: 40%">
                                <Input type="text" size="default"   v-model="netCarCompanyForm.examineRemark" clearable  placeholder="请输入" style="width: 400px"/>
                            </FormItem>
                        </i-col>

                    </Row>
                    <Row>
                        <i-col span="12">
                            <FormItem label="退回原因" prop="examineReason"   style="margin-left: 40%">
                                <Input type="text" size="default"   v-model="netCarCompanyForm.examineReason" clearable  placeholder="请输入原因" style="width: 400px"/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <h2 class="title-text"><span>网约车</span></h2>
                        <Row>
                            <i-col span="8">
                                <Form-item label="运营公司名称" prop="affiliatedName"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.affiliatedName" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="社会统一信用代码" prop="socUniCrtCode"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.socUniCrtCode" clearable placeholder="请输入"
                                           style="width: 200px" />
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="已运营年限" prop="operationYears"  >
                                    <Input disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.operationYears" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="8">
                                <div v-for="(item,index) in netCarCompanyForm.addressinfotwo" :key="index">
                                    <FormItem label="运营城市" :prop="'addressinfotwo['+index+'].detailAddresstwo'"
                                              :style="{'z-index':'99'-index,'position':'relative'}">

                                        <Cascader v-bind:disabled="disabled" :load-data="loadData" :data="location" style="width:200px;" size="default"
                                                  v-model="item.detailAddresstwo" placeholder="下拉选择省市" class="show_cascader_input" :clearable="false">
                                        </Cascader>

                                    </FormItem>
                                </div>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="注册时间" prop="foundedTime"  >
                                    <Date-picker v-bind:disabled="disabled" type="date" size="default"  v-model="netCarCompanyForm.foundedTime"  placeholder="选择日期" style="width: 200px"></Date-picker>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="在运营网约车数量" prop="operateVehicles"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.operateVehicles" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="8">
                                <Form-item label="注册资本" prop="registeredCapital"    >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.registeredCapital" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="法人姓名" prop="legalPersonName"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.legalPersonName" clearable placeholder="请输入"
                                           style="width: 200px" />
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="人证完备数" prop="peopleCardComplete"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.peopleCardComplete" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="8">
                                <Form-item label="联系方式" prop="legalPersonTel"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.legalPersonTel" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>

                            </i-col>
                            <i-col span="8">
                                <Form-item label="合作平台" prop="cooperPlat"  >
                                    <Select v-bind:disabled="disabled" v-model="netCarCompanyForm.cooperPlat" multiple size="default"  style="width: 200px">
                                        <Option v-for="item in cooperList" :value="item.code" :key="item.code" :label="item.name">{{ item.name }}
                                        </Option>
                                    </Select>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="车证完备数" prop="carCardComplete"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.carCardComplete" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="8">
                                <Form-item label="法人身份证号码" prop="legalPersonIdcard"  >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.legalPersonIdcard" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="网约车合作有效期" prop="oprTermValidity"  >
                                    <i-col span="12">
                                        <Date-picker v-bind:disabled="disabled" type="date" size="default"  v-model="netCarCompanyForm.oprTermValidity"  placeholder="选择日期" style="width: 200px"></Date-picker>
                                    </i-col>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <FormItem label="人证+车证完备数" prop="peoCarCardComplete" >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.peoCarCardComplete" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="8">
                                <div v-for="(item,index) in netCarCompanyForm.addressinfo" :key="index">
                                    <FormItem label="注册省市" :prop="'addressinfo['+index+'].detailAddress'"
                                              :style="{'z-index':'99'-index,'position':'relative'}">
                                        <Cascader v-bind:disabled="disabled" :load-data="loadData" :data="location" style="width:200px;" size="default"
                                                  v-model="item.detailAddress" placeholder="下拉选择省市" class="show_cascader_input" :clearable="false">
                                        </Cascader>

                                    </FormItem>
                                </div>
                            </i-col>
                            <i-col span="8">
                                <form-item label="详细地址" prop="registeredAddress">
                                    <Input  v-bind:disabled="disabled" v-model="netCarCompanyForm.registeredAddress" size="default" style="width: 200px" placeholder="请输入" />
                                </form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="人证+车完备比例（%）" prop="peoCarCardProportion" >
                                    <Input v-bind:disabled="disabled" type="text" size="default" v-model="netCarCompanyForm.peoCarCardProportion" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                        </Row>
                        <Row>
                            <i-col span="8">
                                <Form-item label="预警值" prop="warningValue">
                                    <Input type="text"   size="default" v-model="netCarCompanyForm.warningValue" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <Form-item label="限额值" prop="limitValue">
                                    <Input type="text"   size="default" v-model="netCarCompanyForm.limitValue" clearable placeholder="请输入"
                                           style="width: 200px"/>
                                </Form-item>
                            </i-col>
                            <i-col span="8">
                                <FormItem label="申请时间" id="applyTime">
                                    <Date-picker  type="date" v-model="netCarCompanyForm.applyTime" size="default"  disabled style="width: 200px"></Date-picker>
                                </FormItem>

                            </i-col>
                        </Row>
                    <Row>
                        <i-col span="8">
                            <Form-item label="是否在库" :label-width="200" prop="isOrNo">
                                <Checkbox v-bind:disabled="disabled"  v-model="isOrNo" value="false"></Checkbox>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="合作商名称" prop="channelId">
                                <Select v-model="netCarCompanyForm.channelId" v-bind:disabled="disabled"  clearable style="width: 200px;" size="default" >
                                    <Option v-for="item in channelList"  :value='item.id' :key="item.id">{{ item.channelFullName }}
                                    </Option>
                                </Select>
                            </Form-item>
                        </i-col>
                    </Row>
            </Form>
            </Row>
        </div>
        <div v-if="index==1">
            <file-operation :uploadParam="uploadParam" :isInt="canUpload" :path="path" readOnly ></file-operation>
        </div>
    </div>
</template>
<script>
    import {examineThirdOrNetCar,saveThirdOrNetCar} from "@/projects/afs-channel/api/affiliation/examineThirdOrNetCar";
    import {getAffiliationInfo} from "@/projects/afs-channel/api/affiliation/affiliationAddEdit";
    import { getLocation,getBaseInfo} from "@/projects/afs-channel/api/common/common";
    import { getDictDataByType } from "@/projects/basic/api/admin/datadic";
    import FileOperation from "_p/basic/pages/image/upload-file/fileOperation.vue";

    export default {
        components: {FileOperation},
        data() {
            const isPositiveInteger = (rule, value, callback) => {
                var reg = /^[0-9]+[0-9]*[0-9]*$/;
                if (!reg.test(value)) {
                    callback(new Error("请输入正整数"));
                } else {
                    callback();
                }
            };
            return {
                canUpload: false,
                uploadParam: {
                    busiNo: "",
                    belongNo: "",
                    busiType: "",
                    busiData: {}
                },
                path:"channel",
                index:0,
                operCity:[],
                location:[],
                channelList:[],
                statusList:[],
                channelId:'',
                bizDataId:'',
                cooperList:[],
                saleDate: '',
                isShowFile: false,
                disabledSingle: true,
                disabledGroup: '是',
                loading: true,
                operationLoading: false,
                importLoading: false,
                loadingExport: true,
                disabled:null,
                drop: false,
                isOrNo:false,
                longTermOrNot:false,
                viewImage: false,
                modalType: 0,
                userModalVisible: false,
                netCarCompanyForm: {
                    channelId:'',
                    affiliatedName:'',
                    socUniCrtCode: "",
                    operationYears:'',
                    foundedTime:'',
                    operateVehicles:'',
                    registeredCapital:'',
                    legalPersonName:'',
                    peopleCardComplete:'',
                    legalPersonTel:'',
                    cooperPlat:[],
                    carCardComplete:'',
                    legalPersonIdcard:'',
                    oprTermValidity:'',
                    peoCarCardComplete:'',
                    registeredProvince:"",
                    registeredCity:"",
                    registeredAddress:'',
                    peoCarCardProportion:'',
                    limitValue:'',
                    warningValue:'',
                    status:"", //修改的状态状态
                    examineRemark:"", // 修改的备注
                    examineReason:"", // 原因
                    bizDataId:'',
                    // 省市用的
                    position: "",
                    // 地址信息
                    addressinfo: [
                        {
                            detailAddress: [],

                        }
                    ],addressinfotwo: [
                        {
                            detailAddresstwo: [],

                        }
                    ]
                },
                fileFrom: {
                    productName: ""
                },
                companyFormValidate: {
                    status: [
                        {required: true, message: "请选择审核意见", trigger: "blur"},
                        // {validator: validateExamineReason, trigger: "blur"}
                    ],
                    warningValue:[
                        {required: true, message: "请填写预警值", trigger: "blur"},
                        {required:true,validator: isPositiveInteger, trigger: "blur"}

                    ],
                    limitValue:[
                        {required: true,message: "请填写限额值", trigger: "blur"},
                        {required:true,validator: isPositiveInteger, trigger: "blur"}

                    ]
                },
                submitLoading: false
            };
        },
        methods: {
            init() {
                this.getTime();
                this.getChannelList();
                this.netCarCompanyForm.id=this.afs.getPageParams(this).id;
                this.channelId=this.afs.getPageParams(this).channelId;
                this.bizDataId = this.afs.getPageParams(this).bizDataId;
                this.getById();
            },
            changeStatus(v){
                if(v==="00"){
                    this.companyFormValidate.warningValue=[{required: true, message: "请填写预警值", trigger: "blur"}, {validator: this.isPositiveInteger, trigger: "blur"}];
                    this.companyFormValidate.limitValue=[{required: true, message: "请填写限额值", trigger: "blur"}, {validator: this.isPositiveInteger, trigger: "blur"}];
                }else{
                    this.companyFormValidate.warningValue=[];
                    this.companyFormValidate.limitValue=[];
                }
            },
            // 根据id 去查询数据
            getById() {
                getAffiliationInfo({id:this.netCarCompanyForm.id}).then(res => {
                    this.operationLoading = false;
                    if (res.code === "0000") {
                        this.disabled="disabled";
                        this.isOrNo=res.data.inLibraryOrNot;
                        this.netCarCompanyForm = res.data;
                        this.netCarCompanyForm.channelId=this.channelId;
                        this.netCarCompanyForm.bizDataId=this.bizDataId;
                        this.netCarCompanyForm.operationYears=this.netCarCompanyForm.operationYears.toString();
                        this.netCarCompanyForm.registeredCapital=this.netCarCompanyForm.registeredCapital.toString();
                        this.netCarCompanyForm.operateVehicles=this.netCarCompanyForm.operateVehicles.toString();
                        this.netCarCompanyForm.peoCarCardComplete=this.netCarCompanyForm.peoCarCardComplete.toString();
                        // 地址信息
                        this.netCarCompanyForm.addressinfo= [{detailAddress: [this.netCarCompanyForm.registeredProvince,this.netCarCompanyForm.registeredCity],}];
                        this.netCarCompanyForm.operCity=this.netCarCompanyForm.operCity.split(",");
                        this.netCarCompanyForm.addressinfotwo= [{detailAddresstwo: [this.netCarCompanyForm.operCity[0],this.netCarCompanyForm.operCity[1]],}];
                        let cooper=this.netCarCompanyForm.cooperPlat.split(",");
                        this.netCarCompanyForm.cooperPlat=cooper;
                        if(typeof this.isOrNo == "undefined" || this.isOrNo =="0"){
                            this.isOrNo=false;
                        }else if(this.isOrNo==="1"){
                            this.isOrNo=true;
                            this.netCarCompanyForm.warningValue=this.netCarCompanyForm.warningValue.toString();
                            this.netCarCompanyForm.limitValue=this.netCarCompanyForm.limitValue.toString();
                        }
                    }
                });
            },
            getCooperList() {
                this.cooperList=[{code: "01", name: "滴滴"}, {code: "02", name: "快车"}, {code: "03", name: "百度"}, {code: "04", name: "大众"}];
            },
            Commit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        if(this.netCarCompanyForm.status==='00'){
                            var reg = /^[0-9]+[0-9]*[0-9]*$/;
                            if(typeof this.netCarCompanyForm.limitValue==="undefined" ||this.netCarCompanyForm.limitValue===""){
                                this.$Message.error("限额值不能为空");
                                return;
                            }
                            if(typeof this.netCarCompanyForm.warningValue==="undefined" || this.netCarCompanyForm.warningValue===""){
                                this.$Message.error("预警值不能为空");
                                return;
                            }
                            if (!reg.test(Number.parseFloat(this.netCarCompanyForm.limitValue))) {
                                this.$Message.error("限额值为正整数");
                                return;
                            }
                            if (!reg.test(Number.parseFloat(this.netCarCompanyForm.warningValue))) {
                                this.$Message.error("预警值为正整数");
                                return;
                            }
                        }
                        if(Number.parseFloat(this.netCarCompanyForm.warningValue)>Number.parseFloat(this.netCarCompanyForm.limitValue)){
                            this.$Message.error("预警值不能大于限额值");
                            return;
                        }
                        let cooperPlat = "";
                        let arrCooperPlat = this.netCarCompanyForm.cooperPlat;
                        for (let i = 0; i < arrCooperPlat.length; i++) {
                            if (i == arrCooperPlat.length - 1) {
                                cooperPlat += arrCooperPlat[i];
                            } else {
                                cooperPlat += arrCooperPlat[i] + ",";
                            }
                        };
                        this.netCarCompanyForm.cooperPlat = cooperPlat;
                        this.netCarCompanyForm.registeredProvince=this.netCarCompanyForm.addressinfo[0].detailAddress[0];
                        this.netCarCompanyForm.registeredCity=this.netCarCompanyForm.addressinfo[0].detailAddress[1];
                        this.netCarCompanyForm.operCity=this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[0]+","+this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[1];
                            examineThirdOrNetCar(this.netCarCompanyForm).then(res => {
                                this.submitLoading = false;
                                if (res.code === "0000") {
                                    this.$Message.success("操作成功");
                                    this.userModalVisible = false;
                                    if(res.data!="") {
                                        let param = {id: res.data};
                                        saveThirdOrNetCar(param);
                                    }
                                    this.afs.closeTab(this);
                                    this.$router.push({path: '/affiliationApplyNetCar'});
                                }
                            });
                    } else {
                        this.$Message.error('请补全信息');
                    }
                })
            },
            closeThisTag(){
                this.afs.closeTab(this);
            },
            getTime() {
                var date = new Date();
                var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
                var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
                var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
                var hours = date.getHours(); //小时 ,返回 Date 对象的小时 (0 ~ 23)
                var minutes = date.getMinutes(); //分钟 ,返回 Date 对象的分钟 (0 ~ 59)
                var seconds = date.getSeconds(); //秒 ,返回 Date 对象的秒数 (0 ~ 59)
                //修改月份格式
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                //修改日期格式
                if (day >= 0 && day <= 9) {
                    day = "0" + day;
                }
                //修改小时格式
                if (hours >= 0 && hours <= 9) {
                    hours = "0" + hours;
                }
                //修改分钟格式
                if (minutes >= 0 && minutes <= 9) {
                    minutes = "0" + minutes;
                }
                //修改秒格式
                if (seconds >= 0 && seconds <= 9) {
                    seconds = "0" + seconds;
                }
                //格式(yyyy-mm-dd hh:mm:ss)
                var currentFormatDate =
                    year +
                    "-" +
                    month +
                    "-" +
                    day +
                    " " +
                    hours +
                    ":" +
                    minutes +
                    ":" +
                    seconds;
                this.netCarCompanyForm.applyTime = currentFormatDate;
            },
            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                })
            },
            loadData(item, callback) {
                // console.log("是否调用新车")
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },
            showPhote(){
                alert("影像资料");
            },
            getChannelList() {
                let params={status:"00"};
                getBaseInfo(params).then(res => {
                    this.operationLoading = false;
                    if (res.code === "0000") {
                        this.channelList=res.data;
                    }
                });
            },
            getStatus() {
                let param = {
                    type: "affiliationExamine"
                };
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.statusList = res.data;
                    }
                });
            },
            clickType(type) {
                this.index = type;
                if(this.index=="1"){
                    console.log("影像件上传!")
                    this.initGetFilterParams();
                }
            },
            // 获取附件数据
            initGetFilterParams() {
                console.log(this.netCarCompanyForm.id);
                this.uploadParam.busiNo = this.netCarCompanyForm.id;
                this.uploadParam.belongNo = this.netCarCompanyForm.id;
                this.uploadParam.busiData = {};
                this.uploadParam.busiType = "affiliateApplyNet";
                this.canUpload = true;
            },
        },
        mounted() {
            this.init();
            this.getChannelList();
            this.getStatus();
            this.getCooperList();
            this.getLocationData();
        }
    }
</script>

<style scoped>

</style>
